public class Queue  {
    /**
     * Construct the Queue.
     */
    private Node hd;
    private Node tl;
    public Queue( ) {
        hd = null;
        tl = null;
    }
    
    /**
     * Test if the stack is logically empty.
     * @return true if empty, false otherwise.
     */
    public boolean isNull( ) {
        return hd == null;
    }
    
    /**
     * Make the stack logically empty.
     */
    /*
    public void destroy( ) {
        hd = null;
    }
    */
    /**
     * Insert a new item into the stack.
     * @param x the item to insert.
     */
    public void pushQ( char symb ) {
    	if(tl == null)
    	{
    		tl= new Node();
    		hd=tl;
    		tl.symb = symb;
    		tl.next = null;
    	}
    	else
    	{
    		Node p;
    		p = new Node();
    		p.symb = symb;
    		p.next = null;
    		tl.next = p;
    		tl = p;
    	}
 
    }
    
    /**
     * Remove the most recently inserted item from the stack.
     * @throws UnderflowException if the stack is empty.
     */
    public void popQ( ) 
    {
       if(hd==tl)
    	   hd=tl= null;
       else
    	   hd=hd.next;
    }
    
    /**
     * Get the most recently inserted item in the stack.
     * Does not alter the stack.
     * @return the most recently inserted item in the stack.
     * @throws UnderflowException if the stack is empty.
     */
    public char topQ( ) {
        if( hd==null )
            {
        		System.err.println("Error: top(null) \n");
        		System.exit(1);
        		return 3;
            }
        else
        	return hd.symb;
    }
}
